﻿using System.Windows;

namespace HeritageAcademy.Window
{
    /// <summary>
    /// Main window class.
    /// </summary>
    public partial class Window
    {
        #region Parameters
        private const double IdealReadingHeight = 850.0;
        private const double IdealReadingWidth = 1000.0;
        private const double Threshold = 50;
        #endregion

        #region Ctor
        /// <summary>
        /// Constructor where we initialize components.
        /// RoutedEventHandler named Window_Loaded is added.
        /// </summary>
        public Window()
        {
            InitializeComponent();
            SetInitialWindowSize();
        }       
        #endregion

        #region Private Methods
        
        /// <summary>
        /// Set most comfortable for reading initial window size.
        /// </summary>
        private void SetInitialWindowSize()
        {
            // TODO: do we want to save the user's previous window size??
            var screenWidth = SystemParameters.FullPrimaryScreenWidth;
            var screenHeight = SystemParameters.FullPrimaryScreenHeight;

            // on big screens we want to default to the ideal reading size
            if (screenWidth > (IdealReadingWidth + Threshold) && screenHeight > (IdealReadingHeight + Threshold))
            {
                Width = IdealReadingWidth;
                Height = IdealReadingHeight;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
                WindowState = WindowState.Normal;
            }

            // on smaller screens we want to size down to a smaller size for when the app
            // restored, but then maximize to fill the window
            else
            {
                Width = screenWidth - Threshold;
                Height = screenHeight - Threshold;
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
                WindowState = WindowState.Maximized;
            }
        }

        #endregion
    }
}
